package com.woniu.springboot.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

@Entity
@Table(name = "teacher")
public class Teacher implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "tid")
	private Integer tid;
	@Column(name = "tname")
	private String tname;
	
	//, fetch = FetchType.LAZY
	@ManyToMany(targetEntity = Student.class)
	@JoinTable(name = "student_teacher", 
		joinColumns = @JoinColumn(name = "tid"),
		inverseJoinColumns = @JoinColumn(name = "sid"))
	@Cascade(value = CascadeType.SAVE_UPDATE)
	@NotFound(action=NotFoundAction.IGNORE)
	private List<Student> students;
	
	public Integer getTid() {
		return tid;
	}
	public void setTid(Integer tid) {
		this.tid = tid;
	}
	public String getTname() {
		return tname;
	}
	public void setTname(String tname) {
		this.tname = tname;
	}
	public List<Student> getStudents() {
		return students;
	}
	public void setStudent(List<Student> students) {
		this.students = students;
	}
	@Override
	public String toString() {
		return "Teacher [tid=" + tid + ", tname=" + tname + "]";
	}
	
}
